package com.houmeiyuan.huiguniang;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisClientConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;

import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * @author wzn
 * @date 219-07-18 12:43
 */
@Configuration/*配置redis模板文件*/
public class RedisConfig {
    @Value("${spring.redis.host}")
    private String hostname;
    @Value("${spring.redis.port}")
    private int port;
    @Value("${spring.redis.password}")
    private String password;
    //@Value("${spring.redis.redis.jedis.pool.max-active}")
   //private int max_active;
    //@Value("${spring.redis.jedis.pool.max-idle}")
    //private int max_idle;
    //@Value("${spring.redis.jedis.pool.max-wait}")
    //private int max_wait;
    //@Value("${spring.redis.jedis.pool.min-idle}")
    //private int min_idle;
    //@Value("${spring.redis.timeout}")
    //private int timeout;

    public RedisConfig() {
    }

    /*redisTemplate模板*/
    @Bean
    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<String, Object>();
        redisTemplate.setConnectionFactory(factory);
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
        redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
        redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        redisTemplate.setEnableTransactionSupport(true);
        return redisTemplate;
    }
}
    
    
 /*  //1.创建JedisPoolConfig对象,在该对象中完读一些链接池配置
    @Bean
    @ConfigurationProperties(prefix="spring.redis.pool")
    public JedisPoolConfig jedisPoolConfig(){
        JedisPoolConfig config=new JedisPoolConfig();
//最大空闲数
        config.setMaxIdle(max_idle);
//最小空阴数
        config.setMinIdle(min_idle);
//景大链接数
        config.setMaxTotal(max_active);

        return config;
}*/

/*
 //2.创建JedisConnectionFactory,配置redis链接信息
@Bean
@ConfigurationProperties(prefix="spring.redis")
public JedisConnectionFactory jedisconnectionFactory(JedisPoolconfig config) {
    JedisConnectionFactory factory = new JedisconnectionFactory();
    //关联连按绝的配置对象
    factory.setPoolConfig(config):
    //配置链格Redis的信息
    //主机地址
    factory.setHostName(hostname):
    //端口
    factory.setPort(port);
    //密码
    factory.setPassword(password);
    //索引
    factory.setDatabase(0);
    return factory;
}*/
